package com.vincent.sciinfo.service.impl;

import com.vincent.sciinfo.mapper.MessageMapper;
import com.vincent.sciinfo.pojo.Message;
import com.vincent.sciinfo.pojo.MessageExample;
import com.vincent.sciinfo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageMapper messageMapper;

    /**
     * 查询所有系统消息
     *
     * @return 返回所有消息。
     */
    @Override
    public List<Message> selectSystemMsg() {
        MessageExample messageExample = new MessageExample();
        MessageExample.Criteria criteria = messageExample.createCriteria();
        criteria.andTouserEqualTo("allTeacher");  //给所有教师的信息
        return messageMapper.selectByExample(messageExample);
    }

    /**
     * 查询某个教师的私信
     *
     * @param teacherId 要查询的教师的Id
     * @return 返回这个教师的私信列表
     */
    @Override
    public List<Message> selectMsgByTeacherId(String teacherId) {
        MessageExample messageExample = new MessageExample();
        MessageExample.Criteria criteria = messageExample.createCriteria();
        criteria.andTouserEqualTo(teacherId);
        return messageMapper.selectByExample(messageExample);
    }

    @Override
    public int insertMessage(Message message) {
        return messageMapper.insert(message);
    }

}
